<?php
namespace Home\Controller;
use Think\Controller;
class TfController extends Controller{
    public function index(){
        $this->tf();
        $this->display();
    }
    private function tf(){
        $zf=0;
        $pd=$this->pd();
        $selects=$this->selects();
        $tk=$this->tk();
        $zf=$pd+$selects+$tk;
        $this->assign('zf',$zf);
        $this->assign('pd',$pd);
        $this->assign('selects',$selects);
        $this->assign('tk',$tk);
    }
    private function pd(){
        $pd_fs=$_POST['pd'];
        $fs=0;
        $tid=I('id');
        $pd=M('pd');
        $list=$pd->where("`tid`=".$tid)->select();
        $count=$pd->where("`tid`=".$tid)->count();
        foreach ($list as $v){
            $data=$v;
            for($i=1;$i<=$count;$i++){
                if($i==$data['id']){
                    if(I('pd'.$i)==$data['success']){
                        $fs=$fs+$pd_fs;
                    }
                }else{
                    $fs+=0;
                }
            }
        }
        return $fs;
    }
    private function selects(){
        $selects_fs=I('selects');
        $fs=0;
        $tid=I('id');
        $selects=M('selects');
        $list=$selects->where("`tid`=".$tid)->select();
        $count=$selects->where("`tid`=".$tid)->count();
        foreach ($list as $v){
            $data=$v;
            for($i=1;$i<=$count;$i++){
                if($i==$data['id']){
                    if(I('selects'.$i)==$data['success']){
                        $fs=$fs+$selects_fs;
                    }
                }else{
                    $fs+=0;
                }
            }
        }
        return $fs;
    }
    private function tk(){
        $tk_fs=$_POST['tk'];
        $fs=0;
        $tid=I('id');
        $tk=M('tk');
        $list=$tk->where("`tid`=".$tid)->select();
        $count=$tk->where("`tid`=".$tid)->count();
        foreach ($list as $v){
            $data=$v;
            for($i=1;$i<=$count;$i++){
                if($i==$data['id']){
                    if(I('tk'.$i)==$data['success']){
                        $fs=$fs+$tk_fs;
                    }
                }else{
                    $fs+=0;
                }
            }
        }
        return $fs;
    }
}